package com.base.common;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.base.util.oConvertUtils;

/**
  * @ClassName: BaseTag
  * @Description: 自定义头部js、css导入标签
  * @date 2015年4月11日 上午9:13:41
  * @Author 杨浩
 */
public class BaseTag extends TagSupport {

	private static final long serialVersionUID = 1L;
	protected String type = "default";// 加载类型

	public void setType(String type) {
		this.type = type;
	}

	@Override
	public int doStartTag() throws JspException {
		return EVAL_PAGE;
	}

	@Override
	public int doEndTag() throws JspException {
		try {
			JspWriter out = this.pageContext.getOut();
			StringBuffer sb = new StringBuffer();
			String webRoot = "\""+((HttpServletRequest) pageContext.getRequest()).getContextPath()+"/";
			
			String types[] = type.split(",");
			if (oConvertUtils.isIn("jquery", types)) {
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/jquery.min.js\"></script> \n");
			}
			if (oConvertUtils.isIn("autocomplete", types)) {
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/mytool/plugin/jquery-1.7.1.min.js\"></script> \n");
				sb.append("<link rel=\"stylesheet\" href="+webRoot+"static_resources/css/autocomplete/jquery.autocomplete.css\" type=\"text/css\"></link> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/mytool/plugin/jquery.autocomplete.js\"></script> \n");
			}
			if (oConvertUtils.isIn("jqueryui", types)) {
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/jquery-ui-1.10.3.min.js\"></script> \n");
			}
			if (oConvertUtils.isIn("easyui", types)) {
				sb.append("<link rel=\"stylesheet\" href="+webRoot+"static_resources/css/themes/ui-cupertino/easyui.css\" type=\"text/css\"></link> \n");
				sb.append("<link rel=\"stylesheet\" href="+webRoot+"static_resources/css/themes/icon.css\" type=\"text/css\"></link> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/easyui/jquery.easyui.min.js\"></script> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/easyui/local/easyui-lang-zh_CN.js\"></script> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/mytool/plugin/plugin_validate_ext.js\"></script> \n");
			}
			
			if (oConvertUtils.isIn("treequery", types)) {
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/mytool/plugin/plugin_tree_query.js\"></script> \n");
			}
			
			if (oConvertUtils.isIn("my97", types)) {
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/My97DatePicker/WdatePicker.js\"></script> \n");
			}
			if (oConvertUtils.isIn("idtabs", types)) {
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/jquery.idTabs.min.js\"></script> \n");
			}
			if (oConvertUtils.isIn("lhgdialog", types)) {
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/lhgdialog/lhgdialog.min.js\"></script> \n");
			}
			if (oConvertUtils.isIn("dataTables", types)) {
//				sb.append("<link rel=\"stylesheet\" href="+webRoot+"static_resources/css/datatables/bootstrap.min.css\" type=\"text/css\"></link> \n");
				sb.append("<link rel=\"stylesheet\" href="+webRoot+"static_resources/css/datatables/bootstrap.css\" type=\"text/css\"></link> \n");
				sb.append("<link rel=\"stylesheet\" href="+webRoot+"static_resources/css/datatables/dataTables.bootstrap.css\" type=\"text/css\"></link> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/jquery.dataTables.min.js\"></script> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/javascript/dataTables.bootstrap.js\"></script> \n");
			}
			if (oConvertUtils.isIn("ztree", types)) {
				sb.append("<link rel=\"stylesheet\" href="+webRoot+"static_resources/plugin/jquery-zTree/css/demo.css\" type=\"text/css\"></link> \n");
				sb.append("<link rel=\"stylesheet\" href="+webRoot+"static_resources/plugin/jquery-zTree/css/icon.css\" type=\"text/css\"></link> \n");
				sb.append("<link rel=\"stylesheet\" href="+webRoot+"static_resources/plugin/jquery-zTree/css/zTreeStyle/zTreeStyle.css\" type=\"text/css\"></link> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/plugin/jquery-zTree/js/jquery.ztree.all-3.5.min.js\"></script> \n");
			}
			/*if (oConvertUtils.isIn("ueditor", types)) {
//				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/plugin/ueditor1.4.3/ueditor.config.js\"></script> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/plugin/ueditor/help_util.js\"></script> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/plugin/ueditor/ueditor.config.js\"></script> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/plugin/ueditor/ueditor.all.js\"></script> \n");
			}*/
			if (oConvertUtils.isIn("ueditor", types)) {
				//sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/plugin/ueditor/lang/zh-cn/zh-cn.js\"></script> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/plugin/ueditor/ueditor.config.js\"></script> \n");
				sb.append("<script type=\"text/javascript\" src="+webRoot+"static_resources/plugin/ueditor/ueditor.all.js\"></script> \n");
			}
//			sb.append("<script type=\"text/javascript\" src=\"static_resources/javascript/select-ui.min.js\"></script> \n");
			sb.append("<link rel=\"stylesheet\" href=\"static_resources/css/style.css\" type=\"text/css\"></link> \n");
//			sb.append("<link rel=\"stylesheet\" href=\"static_resources/css/select.css\" type=\"text/css\"></link> \n");
			sb.append("<link rel=\"stylesheet\" href=\"static_resources/css/ext.css\" type=\"text/css\"></link> \n");
			sb.append("<script type=\"text/javascript\" src=\"static_resources/javascript/mytool/y-common-1.0.js\"></script> \n");
			
			out.print(sb.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

}
